package org.example.test.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.annotations.Param;
import org.example.test.entity.Emp;
import org.example.test.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/emp")
public class EmpController {

    //572
    @Autowired
    private EmpService empService;



    @GetMapping("/emps")
    public Map<String, Object> emps(Integer pageNum, Integer pageSize,String ename) {
        //既存放数据，又存放总条数
        Map<String, Object> map = new HashMap<String, Object>();
        Page<Object> startPage = PageHelper.startPage(pageNum, pageSize);
        map.put("empList", empService.findAll(ename));//向容器中放获取到的数据
        map.put("total", startPage.getTotal());//向容器中放数据总条数
        return map;
    }

    @GetMapping("/delete")
    public int delete(Integer empno) {
        return empService.delete(empno);
    }
    @RequestMapping("/editEmp")
    public int editEmp(@RequestBody Emp emp){
        return  empService.editEmp(emp);
    }
    @RequestMapping("/addEmp")
    public int addEmp(@RequestBody Emp emp){
        return  empService.addEmp(emp);
    }
}
